package cn.elead.it.template.config;

import java.util.concurrent.ThreadPoolExecutor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import com.google.common.eventbus.AsyncEventBus;

/**
 * 本地异步消息配置,基于guava异步消息
 * 
 * @author luopeng
 *
 */
@Configuration
@ComponentScan("cn.elead.it.common.async")
public class EventBusConfig {

	@Bean
	public AsyncEventBus asyncEventBus() {

		ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
		executor.setCorePoolSize(10);
		executor.setMaxPoolSize(50);
		executor.setQueueCapacity(10000);
		executor.setKeepAliveSeconds(300);
		executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
		executor.initialize();
		
		return new AsyncEventBus(executor);
	}
}
